package com.zgkxzx.java.mutilThread.threads;

/**
 * 创建者 zgkxzx
 * 日期   12/18/17
 * 描述
 */

public class MyThread extends Thread {
    private static ThreadLocal<Number> threadLocal = new ThreadLocal<Number>() {
        public Number initialValue() {//为每个线程保存的值进行初始化操作
            return new Number();
        }
    };

    private static Number number = new Number();
    private static int i = 0;

    @Override
    public void run() {
        i++;
        number.setNumber(i);
        threadLocal.set(number);
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        }
        System.out.println(getName() + " i--> " + i);
        //输出num值
        System.out.println(getName() + " number --> " + threadLocal.get().getNumber());
    }
}
